package com.ruoyi.jjm.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.jjm.mapper.ClientUserMapper;
import com.ruoyi.jjm.vo.VillageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.jjm.mapper.VillageMapper;
import com.ruoyi.jjm.domain.Village;
import com.ruoyi.jjm.service.IVillageService;
import com.ruoyi.common.core.text.Convert;

/**
 * 村统计信息Service业务层处理
 * 
 * @author tsr
 * @date 2020-07-15
 */
@Service
public class VillageServiceImpl implements IVillageService
{
    @Autowired
    private VillageMapper villageMapper;

    @Autowired
    private ClientUserMapper clientUserMapper;

    /**
     * 查询村统计信息
     * 
     * @param id 村统计信息ID
     * @return 村统计信息
     */
    @Override
    public Village selectVillageById(Long id)
    {
        return villageMapper.selectVillageById(id);
    }

    /**
     * 查询村统计信息列表
     * 
     * @param village 村统计信息
     * @return 村统计信息
     */
    @Override
    public List<Village> selectVillageList(Village village)
    {
        return villageMapper.selectVillageList(village);
    }

    /**
     * 新增村统计信息
     * 
     * @param village 村统计信息
     * @return 结果
     */
    @Override
    public int insertVillage(Village village)
    {
        village.setCreateTime(DateUtils.getNowDate());
        return villageMapper.insertVillage(village);
    }

    /**
     * 修改村统计信息
     * 
     * @param village 村统计信息
     * @return 结果
     */
    @Override
    public int updateVillage(Village village)
    {
        village.setUpdateTime(DateUtils.getNowDate());
        return villageMapper.updateVillage(village);
    }

    /**
     * 删除村统计信息对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteVillageByIds(String ids)
    {
        return villageMapper.deleteVillageByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除村统计信息信息
     * 
     * @param id 村统计信息ID
     * @return 结果
     */
    @Override
    public int deleteVillageById(Long id)
    {
        return villageMapper.deleteVillageById(id);
    }

    @Override
    public List<VillageInfo> selectVillageInfoByXiang(long xiangId) {
        return villageMapper.selectVillageInfoByXiang(xiangId);
    }

    public VillageInfo selectVillageInfoByVillageId(long villageId) {
        return villageMapper.selectVillageInfoByVillageId(villageId);
    }

    @Override
    public void updateVillagePopulation(Village village) {
        villageMapper.updateVillagePopulation(village);
    }

    @Override
    public Long countVillagePopulation(Long id) {
        Village village = new Village();
        village.setId(id);
        Long population = clientUserMapper.countVillagePopulation(id);
        village.setPopulation(population);
        villageMapper.updateVillagePopulation(village);
        return population;
    }

    @Override
    public VillageInfo selectVillageInfoByXiangId(long xiangId) {
        return villageMapper.selectVillageInfoByXiangId(xiangId);
    }
}
